package com.briup.mt.service.impl;

import com.briup.mt.bean.BaseUser;
import com.briup.mt.bean.BaseUserExample;
import com.briup.mt.dao.BaseUserMapper;
import com.briup.mt.service.IBaseUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author pete
 * @version 1.0
 * @date 2020/12/16 10:22
 */

@Service
public class BaseUserServiceImpl implements IBaseUserService {
 @Resource
    private BaseUserMapper  baseUserMapper;

    @Override
    public List<BaseUser> query(String realname) {
        BaseUserExample example = new BaseUserExample();
        if(!StringUtils.isEmpty(realname)){
            example.createCriteria().andRealnameLike("%" + realname + "%");
        }
        return baseUserMapper.selectByExample(example);
    }
    @Override
    public void SaveOrUpdate(BaseUser baseUser) {
        if(baseUser.getId()==null){
            baseUserMapper.insert(baseUser);
        }else {
            baseUserMapper.updateByPrimaryKey(baseUser);
        }

    }

    @Override
    public void deleteById(long id) {

        baseUserMapper.deleteByPrimaryKey(id);
    }
}

